﻿
using Edge.Repository.Base;
using Edge.Repository.Model;
using HYRN.Common.ConvertUtilities;
using System;
using System.Collections.Generic;
using System.Linq;


namespace Edge.Repository.DAL
{


     

    /// <summary>
    /// 配置数据
    /// </summary>
    public class KeyValService : BaseRepository<CS_KeyVal>
    {

        public void SetConfig(string name, string key, string val)
        {
            CS_KeyVal model = this.Query(F => F.Code == key).FirstOrDefault();

            if (model != null)
            {
                model.Code = key;
                model.Val = val;
                this.Update(model);
            }
            else
            {
                this.Add(new CS_KeyVal()
                {
                    Code = key,
                    Name = name,
                    Type = 0,
                    Val = val
                });
            }

        }



        public string GetConfig(string key)
        {
            CS_KeyVal model = this.Query(F => F.Code == key).FirstOrDefault();

            if (model != null)
            {
                return model.Val;
            }
            else
            {
                return "";
            }
        }

        public List<string> GetCarTypeChecks(string key)
        {
            string CheckCarType_Str = GetConfig(key);

            List<string> strings = new List<string>();
            if (!string.IsNullOrEmpty(CheckCarType_Str))
            {
                strings = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(CheckCarType_Str);
            }
            return strings;
        }

    }


     



}
